#include "ApplyOpOp.h"

ApplyOpOp::ApplyOpOp() : GenericOperation(qApp->translate("Operations", "A&pply Operation").toStdString())
{
    initShortcut(new QKeySequence(QString(qApp->translate("","Ctrl+P"))));
}

void ApplyOpOp::operator()(const genericinterface::ImageWindow* currentWnd, const std::vector<const genericinterface::ImageWindow*>&){
    genericinterface::ImageWindow::Mode mode= genericinterface::ImageWindow::USER;


    ApplyOpDialog* dialog = new ApplyOpDialog(NULL,currentWnd);

    QDialog::DialogCode code = static_cast<QDialog::DialogCode>(dialog->exec());

    if(code!=QDialog::Accepted) {
        return;
    }

    ParamRep * param = dialog->getParam();

    DoubleImageWindow * diw;
    StandardImageWindow * siw;
    ImageWindow * iw = const_cast<ImageWindow *>(currentWnd);

    QString text = iw->processingmade->text();
    //we complete text with the correct processing
    switch(param->getParamInt(ParamRep::OPERATION)){
        case ParamRep::STANDARDCUT:
        text.append(QString(qApp->translate("","Clipping")));        break;
        case ParamRep::STANDARDABS:
        text.append(QString(qApp->translate("","Abs")));        break;
        break;
        case ParamRep::STANDARDNORM:
        text.append(QString(qApp->translate("","Stretch")));        break;
        break;
        case ParamRep::STANDARDROUND:
        text.append(QString(qApp->translate("","Round")));        break;
    }//switch text processing

    string simpletext = text.toStdString();

    if(currentWnd->isDouble()){
        diw = dynamic_cast<DoubleImageWindow *>(iw);

        outDoubleImage(diw->getImage()->applyProcessing(param),simpletext);
    }else if(currentWnd->isStandard()){
        siw = dynamic_cast<StandardImageWindow *>(iw);
        outImage(siw->getImage()->applyProcessing(param),simpletext);
    }
}
